package com.easyliving.app.ui.home;

import android.util.Log;

import androidx.annotation.Nullable;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModel;

import com.easyliving.app.lib.net.ApiResponse;
import com.easyliving.app.lib.net.RemoteLoader;
import com.easyliving.app.lib.net.ResponseObserver;
import com.easyliving.app.service.ICommonService;

public class HomeViewModel extends ViewModel {

    private MutableLiveData<String> mText;

    public HomeViewModel() {
        mText = new MutableLiveData<>();
        mText.setValue("This is home fragment");
    }

    public LiveData<String> getText() {
        RemoteLoader.getDefaultLoader()
                .loadService(ICommonService.class)
                .getPlatformList()
                .observeForever(new ResponseObserver<ApiResponse<Object>>() {
                    @Override
                    public void onSuccess(ApiResponse<Object> s) {
                        Log.e("test", "data:" + s);
                        mText.postValue(s.toString());
                    }

                    @Override
                    public void onFailure() {
                        mText.postValue("load failure!");
                    }
                });
        return mText;
    }
}